# 王磊的作业

import random

# 精美的界面
print("*******************************")
print("*        中国工商银行           *")
print("*******************************")
print("*         1、开户              *")
print("*         2、存钱              *")
print("*         3、取钱              *")
print("*         4、转账              *")
print("*         5、查询              *")
print("*         6、bye              *")
print("*******************************")

# 用户信息字典
bank = {}
# 银行名称
bank_name = "中国工商银行 "


# 开户
def user_info():
    account = random.randint(10000000, 99999999)
    username = input("请输入您的姓名：")
    while True:
        password = input("请输入您的密码：")
        if password.isdigit():
            if 99999 < int(password) < 1000000:
                break
            else:
                print('输入的密码需为六位数！')
        else:
            print('请输入纯数字密码！')
    country = input("\t\t请输入您的国家：")
    province = input("\t\t请输入您的省份：")
    street = input("\t\t请输入您的街道：")
    door = input("\t\t请输入您的门牌号：")
    x = bank_add(account, username, password, country, province, street, door, )
    if x == 1:
        print("开户成功，以下是您的详细信息")
        info = '''
        --------%s--------
        账号:%s
        姓名:%s
        密码:******
        国家:%s
        省份:%s
        街道:%s
        门牌号:%s
        余额:%s
        '''
        print(info % (bank_name, account, username, country, province, street, door, bank[account]["money"]))
    elif x == 2:
        print("账户已存在")
    elif x == 3:
        print("数据库已满")


def bank_add(account, username, password, country, province, street, door, ):
    if len(bank) >= 100:
        return 3
    elif account in bank:
        return 2
    else:
        bank[account] = {
            "username": username,
            "password": password,
            "country": country,
            "province": province,
            "street": street,
            "door": door,
            "money": 0,
            "bankname": bank_name
        }
        return 1


# 存款
def saving():
    hao = int(input("请输入您的账号："))
    money = int(input('请输入存入的金额：'))
    if hao in bank:
        bank[hao]['money'] += money
        return True
    else:
        return False


def cun():
    c = saving()
    if c == True:
        print('存款成功!')
    else:
        print('存款失败！')


# 取钱
def Withdrawal():
    hao = int(input("请输入您的账号："))
    password = input("请输入您的密码：")
    money = int(input('请输入取出的金额：'))
    if hao not in bank:
        return 1
    elif password != bank[hao]['password']:
        return 2
    elif money <= bank[hao]['money']:
        bank[hao]['money'] -= money
        return 0
    else:
        return 3


def qu():
    q = Withdrawal()
    if q == 0:
        print('取款成功！')
    elif q == 1:
        print('输入的账号不存在！')
    elif q == 2:
        print('输入的密码有误！')
    else:
        print('你没钱！')


# 转账
def Transfer():
    fhao = int(input("请输入转出的账号："))
    shao = int(input("请输入转入的账号："))
    password = input("请输入转出账号的密码：")
    money = int(input('请输入转出的金额：'))
    if fhao and shao not in bank:
        return 1
    elif password != bank[fhao]['password']:
        return 2
    elif money <= bank[fhao]['money']:
        bank[fhao]['money'] -= money
        bank[shao]['money'] += money
        return 0
    else:
        return 3


def zhuan():
    q = Transfer()
    if q == 0:
        print('转账成功！')
    elif q == 1:
        print('转出或转入账号不存在！')
    elif q == 2:
        print('转出账号密码有误！')
    else:
        print('你没钱！')


# 查询
def Inquire():
    hao = int(input("请输入查询的账号："))
    password = input("请输入账号的密码：")
    if hao not in bank:
        print('该用户不存在！')
        if password != bank[hao]['password']:
            print('账号密码错误！')
    else:
        info = '''
        --------%s--------
        当前账号:%s
        姓名:%s
        密码:******
        余额:%s
        国家:%s
        省份:%s
        街道:%s
        门牌号:%s
        开户行:%s
        '''
        print(info % (
        bank_name, hao, bank[hao]['username'], bank[hao]['money'], bank[hao]['country'], bank[hao]['province'],
        bank[hao]['street'], bank[hao]['door'], bank_name))


# 程序主体
while True:
    index = input("请选择业务>>>>>")
    if index == "1":
        print("*************开户***************")
        user_info()
    elif index == "2":
        print("*************存钱***************")
        cun()
    elif index == '3':
        print('*************取钱***************')
        qu()
    elif index == '4':
        print('*************转账***************')
        zhuan()
    elif index == '5':
        print('*************查询***************')
        Inquire()
    elif index == '6':
        print('bye!')
        break
    else:
        print('您输入内容有误，请重新输入！')
